package com.iRomantic.config;

import java.util.Properties;

import com.iRomantic.controller.app.BlessAPPController;
import com.iRomantic.controller.app.FeedbackAPPController;
import com.iRomantic.controller.app.HotelAPPController;
import com.iRomantic.controller.app.UserAPPController;
import com.iRomantic.controller.app.VersionAPPController;
import com.iRomantic.controller.app.WeddingAppController;
import com.iRomantic.controller.company.CompanyController;
import com.iRomantic.controller.manager.EnterpriseController;
import com.iRomantic.controller.manager.HotelController;
import com.iRomantic.controller.manager.InvitationController;
import com.iRomantic.controller.manager.ManagerController;
import com.iRomantic.controller.manager.PictureController;
import com.iRomantic.controller.manager.UserController;
import com.iRomantic.controller.manager.VersionController;
import com.iRomantic.controller.manager.VideoController;
import com.iRomantic.controller.manager.WeddingController;
import com.iRomantic.controller.portal.IndexController;
import com.iRomantic.domain.entity.Bless;
import com.iRomantic.domain.entity.Client;
import com.iRomantic.domain.entity.Enterprise;
import com.iRomantic.domain.entity.Feedback;
import com.iRomantic.domain.entity.Hotel;
import com.iRomantic.domain.entity.HotelPicture;
import com.iRomantic.domain.entity.Invitation;
import com.iRomantic.domain.entity.Member;
import com.iRomantic.domain.entity.Picture;
import com.iRomantic.domain.entity.User;
import com.iRomantic.domain.entity.Version;
import com.iRomantic.domain.entity.Video;
import com.iRomantic.domain.entity.Wedding;
import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.plugin.ehcache.EhCachePlugin;
import com.jfinal.render.ViewType;

public class MainConfig extends JFinalConfig {
	
	private Properties jdbc = null;

	/**
	 * 配置常量
	 */
	public void configConstant(Constants me) {
		jdbc = loadPropertyFile("classes/JDBC.properties");
		me.setDevMode(true);
		me.setBaseViewPath("/WEB-INF/web/");
		//设置视图类型为Jsp
		me.setViewType(ViewType.JSP);
	}

	@Override
	public void configRoute(Routes me) {
		
		//me.add(new AutoBindRoutes());
		
		//app Controller
		me.add("/app/user", UserAPPController.class);
		me.add("/app/wedding", WeddingAppController.class);
		me.add("/app/bless", BlessAPPController.class);
		me.add("/app/version", VersionAPPController.class);
		me.add("/app/hotel",HotelAPPController.class);
		me.add("/app/feedback",FeedbackAPPController.class);
		
		
		
		
		//manager Controller
		me.add("/manager",ManagerController.class);
		me.add("/manager/wedding", WeddingController.class);
		me.add("/manager/hotel",HotelController.class);
		me.add("/manager/enterprise",EnterpriseController.class);
		me.add("/manager/picture",PictureController.class);
		me.add("/manager/video",VideoController.class);
		me.add("/manager/version",VersionController.class);
		me.add("/manager/invitation",InvitationController.class);
		me.add("/manager/user",UserController.class);
		
		//portal Controller
		me.add("/", IndexController.class);
		
		//company Controller CompanyController
		me.add("/companyMgr/index", CompanyController.class);
	}

	/**
	 * 配置第三方插件
	 */
	public void configPlugin(Plugins me) {
		// 配置C3p0数据库连接池插件
		C3p0Plugin c3p0Plugin = new C3p0Plugin(jdbc.getProperty("url"), jdbc.getProperty("username"), jdbc.getProperty("password").trim());
		me.add(c3p0Plugin);
		
		//缓存配置
		me.add(new EhCachePlugin());
		
		// 配置ActiveRecord插件
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		arp.setShowSql(true);
		arp.addMapping("t_user", User.class);
		arp.addMapping("t_wedding", Wedding.class);
		arp.addMapping("t_hotel", Hotel.class);
		arp.addMapping("t_enterprise", Enterprise.class);
		arp.addMapping("t_picture", Picture.class);
		arp.addMapping("t_video", Video.class);
		arp.addMapping("t_bless", Bless.class);
		arp.addMapping("t_version", Version.class);
		arp.addMapping("t_hotel_picture", HotelPicture.class);
		arp.addMapping("t_feedback", Feedback.class);
		arp.addMapping("t_invitation", Invitation.class);
		
		//添加t_MEMBER表映射
		arp.addMapping("t_member", Member.class);
		
		//添加t_client表映射
		arp.addMapping("t_client",Client.class);
		me.add(arp);
	}

	@Override
	public void configInterceptor(Interceptors me) {
		

	}

	@Override
	public void configHandler(Handlers me) {
		

	}

}
